package com.daisuxia.risk.utils;

import java.util.Calendar;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.jexl2.Expression;
import org.apache.commons.jexl2.JexlContext;
import org.apache.commons.jexl2.JexlEngine;
import org.apache.commons.jexl2.MapContext;
import org.apache.commons.lang3.StringUtils;

import com.daisuxia.web.pojo.User;
import com.daisuxia.web.util.encrypt.AESUtil;
import com.daisuxia.web.util.encrypt.MD5coding;

public class FormulaUtil {

	/**
	 * 检查公式语法，把所有的唯一标识去掉，刊登否正常得出结果
	 * 
	 * @param formula
	 * @return
	 */
	public static Object checkFormula(String formula) {
		formula = formula.replaceAll(ConstantRisk.RULE_PREFIX, "");
		return calFormula(formula);
	}

	public static Object calFormula(String formula) {
		JexlContext ctxt = new MapContext();
		JexlEngine jexl = new JexlEngine();
		Expression expr = jexl.createExpression(formula);
		return expr.evaluate(ctxt);
	}

	public static void main(String[] args) {
		Calendar now = Calendar.getInstance();
		now.add(Calendar.DAY_OF_YEAR, -1);
		System.out.println(now.getTime());
	}
}
